Java JavaScript Python C# C C++ Go Kotlin PHP Swift R Ruby TypeScript Scala SQL Perl rust VisualBasic Matlab Julia

Python Operators

Operators precedence

list of Python operators in the order of their precedence from highest to lowest:
() Parentheses (highest precedence)
x[index], x[index:index] Subscription, slicing
await x Await expression
** Exponentiation
+x, -x, ~x Positive, negative, bitwise NOT
*, @, /, //, % Multiplication, matrix multiplication, division, floor division, modulus
+, - Addition and subtraction
<<, >> Bitwise shifts
& Bitwise AND
^ Bitwise XOR
| Bitwise OR
in, not in, is, is not, <, <=, >, >=, !=, == Comparisons, membership tests, identity tests
not x Boolean NOT
and Boolean AND
or Boolean OR
if-else Conditional expression
lambda Lambda expression
:= Assignment expression (walrus operator) (lowest precedence)
Please note that operators with higher precedence are evaluated before operators with lower precedence. Operators with the same precedence level are evaluated based on their associativity.

  📌TAGS

★python ★operators

Tutorials